#include "NetworkPlayer.h"

NetworkPlayer::NetworkPlayer(Hand h, int i, game* g,Server* s):Player(h,i,g,s)
{
    localHand=h;
    id=i;
}

void NetworkPlayer::sendHand()
{
    // *
        QString cards="";

        for(int i=0;i<localHand.getHandSize();i++)
        {
            cards.append(localHand.getCard(i)->suit);
            cards.append(QString::fromStdString(localHand.getCard(i)->num));
            cards.append(",");
        }
     server->sendCardArray(id, QString::fromStdString(getUsername()), cards, "Own");
}
void NetworkPlayer::getBid()
{
    //H1
    //NT3
    //PASS
    //H1D

    //getBid(int id)

    // *
     server->getBid( id, QString::fromStdString(getUsername()));
}
Card NetworkPlayer::getMove(bool a)
{
    if(!a)
        server->getMove(id, QString::fromStdString(getUsername()));
    else
        server->getDummyMove(id, QString::fromStdString(getUsername()));
}
void NetworkPlayer::sendBid(QStringList bid, int player)
{
   // *
   server->sendBid(id,QString::fromStdString(getUsername()),bid.at(3), bid.at(0), bid.at(1).toInt(), bid.at(2));
}

void NetworkPlayer::sendMove(Card card,int player)
{
    QString suit="";
    suit.append(card.suit);
    server->sendMove(QString::fromStdString(getUsername()), id,suit,QString::fromStdString(card.num));
}
//startThread(id);
void NetworkPlayer::moveInvalid()
{
    //sendACknowlage(0,5);
}

void NetworkPlayer::bidInvalid()
{
    //sendACknowlage(int id,0,2);
}
void NetworkPlayer::startDealing()
{
    // *
    setUsername("test user");
    qDebug()<<"server start dealing";

    server->sendPhase(id, QString::fromStdString(getUsername()), QString("Dealing"));
    //server->getIP();
}

void NetworkPlayer::startRedealing()
{
      server->sendPhase(id,QString::fromStdString(getUsername()), "Redealing");
}

void NetworkPlayer::startBidding()
{
    // *
      server->sendPhase(id, QString::fromStdString(getUsername()), "Bidding");
}

void NetworkPlayer::startPlay()
{
     server-> sendPhase(id,QString::fromStdString(getUsername()), "Play");
}

void NetworkPlayer::RubberDone()
{
    //  sendPhase(int id, "Rubber Done")
    server-> sendPhase(id,QString::fromStdString(getUsername()), "Rubber Done");
}
void NetworkPlayer::sendTrickWinner(string winner)
{
     //server->sendWonUpdate(id,QString team,QString note);
}
void NetworkPlayer::sendContract(QStringList cont)
{
    //*
    server->sendContract(QString::fromStdString(getUsername()), cont.at(1).toInt(), cont.at(2));
}
void NetworkPlayer::sendDummyId(string dummy)
{
    // *
    server->sendDummyID( id, QString::fromStdString(getUsername()),QString::fromStdString(dummy));
}
void NetworkPlayer::sendDummyCards(Hand dHand)
{
    // *
    QString cards="";

    for(int i=0;i<localHand.getHandSize();i++)
    {
        cards.append(localHand.getCard(i)->suit);
        cards.append(QString::fromStdString(localHand.getCard(i)->num));
        cards.append(",");
    }
    server->sendCardArray( id, QString::fromStdString(getUsername()), cards, "Dummy");
}
void updateScore()
{
    //bool scoreUpdate(int id,QString we_above,QString we_below,QString they_above,QString they_below)
}
void NetworkPlayer::startDummy()
{
    //*
    // null
}
void  NetworkPlayer::sendGameStatus(QStringList a)
{

}
